package com.sc.everyonerentboot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //形参设置允许跨域规则
        registry.addMapping("/**") //设置允许跨域路径
                .allowedOriginPatterns("*") //设置允许跨域的域名
                .allowCredentials(true) //是否允许Cookie
                .allowedMethods("GET","POST","PUT","DELETE") //设置的允许请求方式
                .allowedHeaders("*") //设置允许的头部信息
                .maxAge(3600); //设置每次跨域的时间 单位秒
    }
}
